#ifndef _WX_CUSTOMBUTTON_H_
#define _WX_CUSTOMBUTTON_H_

#include "wx/things/thingdef.h"

class wxTimer;
class wxTimerEvent;

enum wxCustomButton_Style {
  wxCUSTBUT_LEFT = 0x0001,
  wxCUSTBUT_RIGHT = 0x0002,
  wxCUSTBUT_TOP = 0x0004,
  wxCUSTBUT_BOTTOM = 0x0008,
  wxCUSTBUT_NOTOGGLE = 0x0100,
  wxCUSTBUT_BUTTON = 0x0200,
  wxCUSTBUT_TOGGLE = 0x0400,
  wxCUSTBUT_BUT_DCLICK_TOG = 0x0800,
  wxCUSTBUT_TOG_DCLICK_BUT = 0x1000,
  wxCUSTBUT_FLAT = 0x2000
};

class wxCustomButton : public wxControl {
  public:
    wxCustomButton() : wxControl() { Init(); }
    wxCustomButton( wxWindow* parent, wxWindowID id, const wxString& label, const wxPoint& pos = wxDefaultPosition,
                    const wxSize& size = wxDefaultSize, long style = wxCUSTBUT_TOGGLE,
                    const wxValidator& val = wxDefaultValidator, const wxString& name = _T( "wxCustomButton" ) )
      : wxControl() {
      Init();
      Create( parent, id, label, wxNullBitmap, pos, size, style, val, name );
    }
    wxCustomButton( wxWindow *parent, wxWindowID id, const wxBitmap& bitmap, const wxPoint& pos = wxDefaultPosition,
                    const wxSize& size = wxDefaultSize, long style = wxCUSTBUT_TOGGLE,
                    const wxValidator& val = wxDefaultValidator, const wxString& name = _T( "wxCustomButton" ) )
      : wxControl() {
      Init();
      Create( parent, id, wxEmptyString, bitmap, pos, size, style, val, name );
    }
    wxCustomButton( wxWindow *parent, wxWindowID id, const wxString& label, const wxBitmap& bitmap,
                    const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
                    long style = wxCUSTBUT_TOGGLE | wxCUSTBUT_BOTTOM, const wxValidator& val = wxDefaultValidator,
                    const wxString& name = _T( "wxCustomButton" ) )
      : wxControl() {
      Init();
      Create( parent, id, label, bitmap, pos, size, style, val, name );
    }
    virtual ~wxCustomButton();
    bool Create( wxWindow* parent, wxWindowID id, const wxString& label, const wxBitmap &bitmap,
                 const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0,
                 const wxValidator& val = wxDefaultValidator, const wxString& name = _T( "wxCustomButton" ) );
    bool GetValue() const { return m_down % 2 != 0; }
    void SetValue( bool depressed );
    long GetButtonStyle() const { return m_button_style; }
    bool SetButtonStyle( long style );
    wxString GetLabel() const { return m_labelString; }
    void SetLabel( const wxString &label );
    void SetBitmapLabel( const wxBitmap& bitmap );
    void SetBitmapSelected( const wxBitmap& sel ) { m_bmpSelected = sel; CalcLayout( true ); };
    void SetBitmapFocus( const wxBitmap& focus ) { m_bmpFocus = focus; CalcLayout( true ); };
    void SetBitmapDisabled( const wxBitmap& disabled ) { m_bmpDisabled = disabled; CalcLayout( true ); };
    void SetLabel( const wxBitmap& bitmap ) { SetBitmapLabel( bitmap ); }
    const wxBitmap& GetBitmapLabel() const { return m_bmpLabel;    }
    const wxBitmap& GetBitmapSelected() const { return m_bmpSelected; }
    const wxBitmap& GetBitmapFocus() const { return m_bmpFocus;    }
    const wxBitmap& GetBitmapDisabled() const { return m_bmpDisabled; }
    wxBitmap CreateBitmapDisabled( const wxBitmap &bitmap ) const;
    void SetMargins( const wxSize &margin, bool fit = false );
    void SetLabelMargin( const wxSize &margin, bool fit = false );
    wxSize GetLabelMargin() const { return m_labelMargin; }
    void SetBitmapMargin( const wxSize &margin, bool fit = false );
    wxSize GetBitmapMargin() const { return m_bitmapMargin; }
    void SetFocused( bool focused ) { m_focused = focused; Refresh( false ); }
    bool GetFocused() const { return m_focused; }
  protected:
    void OnPaint( wxPaintEvent &event );
    void Redraw();
    virtual void Paint( wxDC &dc );
    virtual wxSize DoGetBestSize() const;
    wxSize DoGetBestSize_T( wxWindow* win ) const;
    virtual void SendEvent();
    void OnMouseEvents( wxMouseEvent &event );
    void OnTimer( wxTimerEvent &event );
    void OnSize( wxSizeEvent &event );
    virtual void CalcLayout( bool refresh );
    int m_down;
    bool m_focused;
    long m_button_style;
    wxString m_labelString;
    wxBitmap m_bmpLabel, m_bmpSelected, m_bmpFocus, m_bmpDisabled;
    wxSize m_labelMargin, m_bitmapMargin;
    wxPoint m_bitmapPos, m_labelPos;
    wxTimer *m_timer;
    wxEventType m_eventType;
  private:
    void Init();
    DECLARE_DYNAMIC_CLASS( wxCustomButton )
    DECLARE_EVENT_TABLE()
};

#endif
